<html>
<head><meta charset="utf-8"><title>fn-return-places · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/fn-return-places.html">fn-return-places</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="136392578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/fn-return-places/near/136392578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/fn-return-places.html#136392578">(Oct 24 2018 at 07:49)</a>:</h4>
<p>Is it true that the return place for function calls is always a local, never a compound path (with projections) or so? Would it be worth encoding that in the type? I plan to rely on that for my Stacked Borrows implementation. (The reason being a local is helpful is that it means I know the place this path evaluates to will be the same after the fn call. If the call is <code>_local[idx] = foo(something)</code>, it might be that <code>foo</code> can mutate <code>idx</code>.)</p>



<a name="136392716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/fn-return-places/near/136392716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/fn-return-places.html#136392716">(Oct 24 2018 at 07:52)</a>:</h4>
<p>I don't think that will be true once we stop being very dumb about return value optimizations, e.g. I think <code>return Foo { x: a(), y: b() }</code> should lower to something like <code>_0.x = a(); _0.y = b();</code> to avoid temporaries</p>



<a name="136396955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/fn-return-places/near/136396955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/fn-return-places.html#136396955">(Oct 24 2018 at 09:23)</a>:</h4>
<p>hm also I found a <code>*_1 = foo()</code></p>



<a name="136397011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/fn-return-places/near/136397011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/fn-return-places.html#136397011">(Oct 24 2018 at 09:24)</a>:</h4>
<p>all of these are fine though, the one thing that does not work is array indices...</p>



<a name="136397467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/fn-return-places/near/136397467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/fn-return-places.html#136397467">(Oct 24 2018 at 09:34)</a>:</h4>
<p>Array indices will definitely show up (e.g., <code>return [foo(), bar()]</code> should write to <code>_0[0]</code> and <code>_0[1]</code>). <em>variable</em> array indices are a bit harder to imagine but could show up in combination with a move forwarding optimization, consider <code>fn foo() -&gt; [i32; 500] { let mut a = [0; 500]; for i in 0..500 { a[i] = f(i); } a }</code> and suppose we eliminate the copy from <code>a</code> into the return place</p>



<a name="136398174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/fn-return-places/near/136398174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/fn-return-places.html#136398174">(Oct 24 2018 at 09:49)</a>:</h4>
<p>I'll just not retag behind array indices for now</p>



<a name="136398235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/fn-return-places/near/136398235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/fn-return-places.html#136398235">(Oct 24 2018 at 09:50)</a>:</h4>
<p>which means the compiler wouldnt be allowed to track aliasing of references stored in arrays as precisely as it does for locals that are directly of ref type</p>



<a name="136398241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/fn-return-places/near/136398241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/fn-return-places.html#136398241">(Oct 24 2018 at 09:50)</a>:</h4>
<p>not perfect, but a start I guess...</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>